package com.thesis.manage.service.utils;

import com.google.common.collect.Lists;
import com.thesis.manage.common.exception.CommonException;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author php
 * @date 2018/2/28
 */
public class TimeFormat {
    public static List<Date> formatDate(String time) {
        ArrayList<Date> result = Lists.newArrayList();
        try {
            int length = 2;
            String[] split = time.split("——");
            if (split.length != length) {
                return null;
            }
            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            result.add(format.parse(split[0]));
            result.add(format.parse(split[1]));
        } catch (Exception e) {
            throw new CommonException("date convert failed", "时间转换异常");
        }
        return result;
    }
}
